package day6;
import day5.TreeNode;
public class ch2 {

    public static int max;
    public int maxPathSum(TreeNode root) {
        max = Integer.MIN_VALUE;
        fun(root);
        return max;


    }

    public int fun(TreeNode node){
        if(node==null) return 0;

        int l = fun(node.left);
        int r = fun(node.right);

        max = Math.max(l+r+node.val,max);

        int num = Math.max(node.val+l,node.val+r);

        return num;

    }


}
